/***************************************************************************
 *
 * $Id: tig.c 2 2009-08-02 11:30:22Z Michael.McTernan $
 *
 * This file is part of tdgen, a timing diagram renderer.
 * Copyright (C) 2005 Michael C McTernan, Michael.McTernan.2001@cs.bris.ac.uk
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 **************************************************************************/

 /** \file
  */
#define FILE_NAME TIG

/*****************************************************************************
 * Header Files
 *****************************************************************************/

#include <stdint.h>
#include <stdio.h>
#include "safe.h"
#include "tig.h"

/*****************************************************************************
 * Interfaces
 *****************************************************************************/

/*****************************************************************************
 * Preprocessor Macros & Constants
 *****************************************************************************/

/*****************************************************************************
 * Typedefs
 *****************************************************************************/

/*****************************************************************************
 * Local Variable Definitions
 *****************************************************************************/


/*****************************************************************************
 * Global Variable Definitions
 *****************************************************************************/

/*****************************************************************************
 * Local Function Definitions
 *****************************************************************************/


/*****************************************************************************
 * Global Function Definitions
 *****************************************************************************/

tig_wave_t     *TigWaveAlloc(const char *label, const char *pattern)
{
    tig_wave_t *r = malloc_s(sizeof(tig_wave_t));

    r->label    = strdup_s(label);
    r->pattern  = strdup_s(pattern);
    r->next     = NULL;
    r->attrList = NULL;

    return r;
}

void            TigWaveDump(const tig_wave_t *wave)
{
    while(wave)
    {
        printf("Wave: %s %s\n", wave->label, wave->pattern);
        TigAttrDump(wave->attrList);
        wave = wave->next;
    }
}

tig_wave_t     *TigWaveLink(tig_wave_t *head, tig_wave_t *n)
{
    tig_wave_t *w = head;

    while(w->next)
    {
        w = w->next;
    }
    w->next = n;

    return head;
}


tig_wave_t     *TigWaveLinkAttr(tig_wave_t *wave, tig_attrlist_t *attrl)
{
    wave->attrList = attrl;

    return wave;
}


tig_attrlist_t *TigAttrAlloc(tig_attr_t a, const char *val)
{
    tig_attrlist_t *r = malloc_s(sizeof(tig_attrlist_t));

    r->attr = a;
    r->val  = strdup_s(val);
    r->next = NULL;

    return r;
}


tig_attrlist_t *TigAttrLink(tig_attrlist_t *head, tig_attrlist_t *n)
{
    tig_attrlist_t *w = head;

    while(w->next)
    {
        w = w->next;
    }
    w->next = n;

    return head;
}


void            TigAttrDump(const tig_attrlist_t *attr)
{
    while(attr)
    {
        printf("  %u->%s\n", attr->attr, attr->val);
        attr = attr->next;
    }
}


/*****************************************************************************
 * Unit Test Support
 *****************************************************************************/


/* END OF FILE */
